package handler

import (
	"github.com/gin-gonic/gin/binding"
	"log"
	"nearby/biz/common"
	"nearby/biz/model"
	"nearby/biz/service"

	"github.com/gin-gonic/gin"
)

// WxLogin [Post] /nearby/user_center/wx_login
func WxLogin(c *gin.Context) {
	// 拿wx_code和app_id换一个登陆token
	// 之后把token塞到cookie里，用来校验用户的身份
	req := &model.WxLoginRequest{}
	if err := c.ShouldBindBodyWith(req, binding.JSON); err != nil {
		c.JSON(400, err.Error())
		return
	}
	log.Printf("WxLogin req: %+v", req.WxCode)
	var ss service.WxLoginService
	resp, err := ss.Execute(c, req)
	log.Printf("WxLogin resp: %+v, err: %+v", resp, err)
	if err != nil {
		common.WriteError(c, err)
		return
	}
	c.JSON(200, resp)
}
